package com.lb.activity.rest;

import com.lb.activity.po.User;
import com.lb.activity.service.UserService;
import com.lb.activity.util.ResultUtil;
import com.lb.activity.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;


/**
 * @author liubin
 */
@RestController
@RequestMapping("user")
@Api(value = "用户管理")
public class UserController {


    @Autowired
    private UserService userService;

    @GetMapping("toUser")
    @ApiOperation(value = "跳转到user页面")
    public ModelAndView toUser(){
        return new ModelAndView("user/user");
    }

    @GetMapping("toUpdate")
    @ApiOperation(value = "跳转到用户修改页面")
    public ModelAndView toUpdate(Long id){
        ModelAndView modelAndView = new ModelAndView("user/user-update");
        modelAndView.addObject("id",id);
        return modelAndView;
    }

    @GetMapping("assignUser")
    @ApiOperation(value = "跳转到角色设置页面",notes = "传递userid")
    public ModelAndView assignUser(Long id){
        ModelAndView modelAndView = new ModelAndView("user/assignRole");
        modelAndView.addObject("userId",id);
        return modelAndView;
    }

    @GetMapping("getOne")
    @ApiOperation(value = "获取单个用户")
    public ResultUtil getOne(Long id){
        UserVo oneById = userService.getOneById(id);
        return ResultUtil.ok(oneById);
    }


    @GetMapping("toAdd")
    @ApiOperation(value = "跳转到用户添加页面")
    public ModelAndView toAdd(){
        return new ModelAndView("user/user-add");
    }

    @GetMapping("list")
    @ApiOperation(value = "分页查询用户",notes = "分页查询")
    public ResultUtil list(UserVo userVo){
        ResultUtil resultUtil =  userService.list(userVo);
        return resultUtil;
    }

    @PostMapping("add")
    @ApiOperation(value = "添加用户")
    public ResultUtil add(User user){
        ResultUtil resultUtil = userService.add(user);
        return resultUtil;
    }

    @PostMapping("update")
    @ApiOperation(value = "更新用户")
    public ResultUtil update(User user){
        ResultUtil resultUtil = userService.update(user);
        return resultUtil;
    }

    @PostMapping("delete")
    @ApiOperation(value = "删除用户")
    public ResultUtil delete(Long id){
        ResultUtil resultUtil = userService.delete(id);
        return resultUtil;
    }

    @PostMapping("changeStatus")
    @ApiOperation(value = "修改用户状态",notes = "lock状态为true")
    public ResultUtil changeStatus(Long id,boolean boolStatus){
        ResultUtil resultUtil = userService.changeStatus(id,boolStatus);
        return resultUtil;
    }




}
